#define  _CRT_SECURE_NO_WARNINGS 1
#include<iostream>

#include<vector>

using namespace std;

//动态规划第一题 





//未空间优化
class Solution {
public:
    int tribonacci(int n) {
        if (n == 0) return 0;
        if (n == 1 || n == 2) return 1;

        vector<int> dp(n + 1);

        dp[0] = 0;
        dp[1] = dp[2] = 1;

        for (int i = 3; i <= n; i++)
        {
            dp[n] = dp[n - 1] + dp[n - 2] + dp[n - 3];

        }

        return dp[n];
    }
};


//空间优化 O(1)
class Solution {
public:
    int tribonacci(int n) {
        if (n == 0) return 0;
        if (n == 1 || n == 2) return 1;

        int a = 0, b = 1, c = 1, d = 0;



        for (int i = 3; i <= n; i++)
        {
            d = a + b + c;
            a = b;
            b = c;
            c = d;
        }

        return d;

    }
};

//动态规划三步问题
class Solution {
public:
    int waysToStep(int n) 
    {




    }
};


//前缀和
int main() {
    //输入两个整数
    int n, m;
    cin >> n >> m;

    vector<int> arr(n + 1);
    for (int i = 1; i <= n; i++) cin >> arr[i];

    vector<long long> dq(n + 1);
    for (int i = 1; i <= n; i++) dq[i] = dq[i - 1] + arr[i];

    int l = 0, r = 0;
    while (m--)
    {
        cin >> l >> r;
        cout << dq[r] - dq[l - 1] << endl;
    }
    return 0;
}